<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <#include "../common/include_easyui.ftl">
    <#assign ctx = request.contextPath>

    <script type="text/javascript">
        var ctxPath = "${ctx}";

        $(function () {

            $('#saveBtn').bind('click', function () {
                saveData();
            });
            $('#reloadBtn').bind('click', function () {
                $("#modifyForm").form("reset");
            });

            // extend the 'equals' rule
            $.extend($.fn.validatebox.defaults.rules, {
                equals: {
                    validator: function (value, param) {
                        return value == $(param[0]).val();
                    },
                    message: '两次密码不一致'
                }
            });
        });

        function saveData() {

            var isValid = jQuery("#modifyForm").form('validate');
            if (!isValid) {
                jQuery("#modifyForm").form('enableValidation');
            } else {

                var saveURL = ctxPath+"/userPersonalController/modifyPersonalPwd?date=" + new Date() + "";
                var paramObj = jQuery("#modifyForm").serializeArray();

                jQuery.post(saveURL, paramObj, function (responseData) {

                    var code = responseData.code;
                    if (code == "200") {
                        $.messager.alert('我的消息', '密码修改成功,请重新登录！', 'info', function () {
                            var parentWin = window.parent;
                            parentWin.location.href = ctxPath+"/securityController/toLogin";
                        });

                    } else {
                        $.messager.alert('我的消息', "密码修改出错，原因 ：" + responseData.message, 'error');
                    }

                }, "json");
            }

        }
    </script>

    <style type="text/css">

        .modify-form div {
            /*	margin-bottom:20px;
                 display: flex;
                justify-content:center; */
        }

    </style>
</head>

<body>
<form id="modifyForm" method="post" class="modify-form">
    <!-- 不可改 -->
    <div style="padding-left:25%;margin-top:80px;">
        <input id="oldPwd" name="oldPwd" class="easyui-passwordbox easyui-validatebox"
               style="margin-left:25%;width: 50%;height:40px;"
               data-options="required:true, labelAlign:'right',label:'旧密码：' ,validType:'length[3,15]',prompt:'请输入旧密码',iconWidth:38,validateOnCreate:false"/>
    </div>
    <div style="padding-left:25%;margin-top:40px;">
        <input id="newPwd" name="newPwd" class="easyui-passwordbox easyui-validatebox"
               style="margin-left:25%;width: 50%;height:40px;"
               data-options="required:true, labelAlign:'right',label:'新密码：' ,validType:'length[3,15]',prompt:'请输入新密码',iconWidth:38,validateOnCreate:false"/>
    </div>
    <div style="padding-left:25%;margin-top:40px;">
        <input id="repeatPwd" name="repeatPwd" class="easyui-passwordbox easyui-validatebox"
               style="margin-left:25%;width: 50%;height:40px;"
               validType="equals['#newPwd']"
               data-options="required:true, labelAlign:'right',label:'确认密码：' ,prompt:'请确认新密码',iconWidth:38,validateOnCreate:false"/>
    </div>

    <div style="margin-top:30px;float: left;width: 100%;">
        <div style="margin-left:35%;float: left;">
            <a id="saveBtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" style="height:35px;">确认修改</a>
        </div>
        <div style="margin-left:5%;float: left;">
            <a id="reloadBtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload'"
               style="height:35px;">重置信息</a>
        </div>
    </div>

</form>

</body>
</html>


